import Vue from 'vue'
import App from './App'

Vue.config.productionTip = false

App.mpType = 'app'

// Vue.prototype.$cloud = uniCloud
Vue.prototype.$showModal = function(content) {
	uni.showModal({
		title: '提示',
		content: content,
		showCancel: false
	})
}

// this.$sendhttp("/Weixin/test.dhtml",{},{},{},'')
Vue.prototype.$sendhttp = function(url, jsonParams, fn, failfn, method) {
	uni.showLoading({
		title: '加载中',
	})
	if (!method) {
		method = 'post'
	}
	let that = this;
	let token = uni.getStorageSync("token");
	token = token ? token : '';
	uni.request({
		url: getApp().globalData.url + url,
		data: jsonParams,
		timeout:30000,
		method: 'post', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
		header: {
			'content-type': 'application/x-www-form-urlencoded',
			'token': token
		},
		success: (res) => {
			console.log('success')
			if (res.data.code == 1) {
				if (fn) {
					fn && fn(res.data.data);
				} else {
					that.$showModal('操作成功');
				}
			} else {
				if (failfn) {
					failfn && failfn(res.data.data);
				} else {
					that.$showModal(res.data.msg);
				}
			}
		},
		fail: function(e) {
			console.log(e)
			that.$showModal('服务器连接错误');
			uni.stopPullDownRefresh();
		},
		complete: (e) => {
			console.log(e);
			uni.hideLoading();
			if(e.data && e.data.sessionout){
				that.$showModal(e.data.msg);
				uni.redirectTo({
					url: '/pages/login/login'
				})
			}
		}
	});
}
const app = new Vue({
	...App
})
app.$mount()
